﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Expo;
using Base;
using Solely;
using MarketSales;

public partial class Member_MarketSales_MarketSalesAdd : nspBase.MemberBasePge
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (CheckCookies())
        {
            if (!IsPostBack)
            {
                Bind();
                int userid = Convert.ToInt32(GetCookie("UserID").ToString());
                int gradeid = Convert.ToInt32(GetCookie("GradeID").ToString());
                if (!Other.CheckUserBussinessCount(gradeid, "expo", userid))
                {
                    Response.Redirect("../ErrorPage.aspx");
                }
            }
        }
        else
        {
            Response.Redirect("../../login/login.aspx");
        }

    }
    private void Bind()
    {
        IExpoType RExpoType = new RExpoType();
        DataTable dt = RExpoType.GetDataTable();
        dropTypeID.DataSource = dt.DefaultView;
        dropTypeID.DataValueField = "ID";
        dropTypeID.DataTextField = "Type";
        dropTypeID.DataBind();

    }
    protected void btnSave_Click(object sender, EventArgs e)
    {
        try
        {
            int userid = Convert.ToInt32(GetCookie("UserID").ToString());
            TMarketSales TMarketSales = new TMarketSales();
            TMarketSales.UserID = userid;
            TMarketSales.Title = Base.Common.RemoveHTML(txtTitle.Text);
            TMarketSales.TypeID = int.Parse(dropTypeID.SelectedValue);
            TMarketSales.StartDate = Convert.ToDateTime(txtStartDate.Text);
            TMarketSales.EndDate = Convert.ToDateTime(txtEndDate.Text);
            TMarketSales.Place = txtPlace.Text;
            TMarketSales.Authorize = txtAuthorize.Text;
            TMarketSales.FrontFor = txtFrontFor.Text;
            TMarketSales.Undertake = txtUndertake.Text;
            TMarketSales.Aidance = txtAidance.Text;
            TMarketSales.Summary = txtSummary.Text;
            TMarketSales.Range = txtRange.Text;
            TMarketSales.Period = dropPeriod.SelectedValue;
            TMarketSales.ExpoType = dropExpoType.SelectedValue;
            TMarketSales.Homepage = txtHomepage.Text;
            TMarketSales.Picture = ImgUrl1.Value;
            if (!string.IsNullOrEmpty(txtShowArea.Text))
            {
                if (GetRequest.isNum(txtShowArea.Text))
                {
                    TMarketSales.ShowArea = int.Parse(txtShowArea.Text);
                }
                else
                {
                    TMarketSales.ShowArea = 0;
                }
            }

            if (!string.IsNullOrEmpty(txtBusinessmen.Text))
            {
                if (GetRequest.isNum(txtBusinessmen.Text))
                {
                    TMarketSales.Businessmen = int.Parse(txtBusinessmen.Text);
                }
                else
                {
                    TMarketSales.Businessmen = 0;
                }
            }

            if (!string.IsNullOrEmpty(txtSpectator.Text))
            {
                if (GetRequest.isNum(txtSpectator.Text))
                {
                    TMarketSales.Spectator = int.Parse(txtSpectator.Text);
                }
                else
                {
                    TMarketSales.Spectator = 0;
                }
            }

            if (!string.IsNullOrEmpty(txtPrice.Text))
            {
                if (GetRequest.isNum(txtPrice.Text))
                {
                    TMarketSales.Price = int.Parse(txtPrice.Text);
                }
                else
                {
                    TMarketSales.Price = 0;
                }
            }

            if (!string.IsNullOrEmpty(txtMinNum.Text))
            {
                if (GetRequest.isNum(txtMinNum.Text))
                {
                    TMarketSales.MinNum = int.Parse(txtMinNum.Text);
                }
                else
                {
                    TMarketSales.MinNum = 0;
                }
            }

            IMarketSales RMarketSales = new RMarketSales();
            int isEmail = 0;
            RMarketSales.Insert(TMarketSales, out isEmail);
            ShowMessage("市场展销信息添加成功！", "MarketSales/MarketSalesList.aspx");
        }
        catch (Exception ex)
        {
            ShowMessage("市场展销信息添加失败！", "MarketSales/MarketSalesList.aspx");
        }
    }
}
